package priv.pront.code.robot.roboCom_na_2022;

import java.io.*;
import java.util.*;

/**
 * @Description: 一个点超时，一个点错误
 * @Author: pront
 * @Time:2023-06-21 17:08
 */
public class RC_v2_智能陪护 {

    static class Info {
        public String no;
        public String type;
        public String time;

        public Info(String no, String type, String time) {
            this.no = no;
            this.type = type;
            this.time = time;
        }

        public Info(String no, String time) {
            this.no = no;
            this.time = time;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Info info = (Info) o;
            return Objects.equals(no, info.no);
        }

        @Override
        public int hashCode() {
            return Objects.hash(no);
        }
    }

    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static int n, m;
    static PriorityQueue<Info> queue = new PriorityQueue<>(new Com());
    static Queue<Integer> robotQueue = new LinkedList<>();
    static Map<String, Integer> relationMap = new HashMap<>();

    static Set<Info> set = new TreeSet<>(new Com2());
    static Set<String> set1 = new HashSet<>();
    static Map<String, String> noTimeRelation = new HashMap<>();

    public static void main(String[] args) throws IOException {
        String[] fLine = bf.readLine().split(" ");
        n = Integer.parseInt(fLine[0]);
        m = Integer.parseInt(fLine[1]);

        for (int i = 1; i <= n; i++) {
            robotQueue.add(i);
        }
        for (int i = 0; i < m; i++) {
            String[] sLine = bf.readLine().split(" ");
            String no = sLine[0];
            String type = sLine[1];
            String time = sLine[2];
            Info info = new Info(no, type, time);
            queue.add(info);
        }

        while (!queue.isEmpty()) {
            Info cur = queue.poll();
            if (cur.type.equals("1")) {
//                如果队列中有机器人
                if (robotQueue.size() > 0) {
                    int robot = robotQueue.poll();
                    relationMap.put(cur.no, robot);
                    out.print(cur.no + " " + "-" + " " + robot);
                    out.println();
                    out.flush();
                } else {
//                如果说队列中没有机器人
                    set.add(new Info(cur.no, cur.time));
                    noTimeRelation.put(cur.no, cur.time);
                    set1.add(cur.no);
                }
            } else if (cur.type.equals("0")) {
                if (robotQueue.size() > 0 && set1.contains(cur.no)) {
                    int poll = robotQueue.poll();
                    out.print(cur.no + " " + "-" + " " + poll);
                    out.println();
                    out.flush();
                    set1.remove(cur.no);
                    set.remove(new Info(cur.no, noTimeRelation.get(cur.no)));
                    robotQueue.add(poll);
                } else if (robotQueue.size() == 0 && set1.contains(cur.no)) {
                    out.print(cur.no + " " + "-" + " " + "NONE");
                    out.println();
                    out.flush();
                    set1.remove(cur.no);
                    set.remove(new Info(cur.no, noTimeRelation.get(cur.no)));
                } else if (!set.contains(new Info(cur.no, cur.time))) {
                    robotQueue.add(relationMap.get(cur.no));
                }
            }
//            下单队列老人等待的处理方式
            while (!set.isEmpty() && robotQueue.size() > 0) {
                boolean flag = false;
                for (Info s : set) {
                    if(robotQueue.size() == 0 || robotQueue.isEmpty()){
                        flag = true;
                        break;
                    }
                    int poll = robotQueue.poll();
                    out.print(s.no + " " + "-" + " " + poll);
                    relationMap.put(s.no, poll);
                    out.println();
                    out.flush();
                    set.remove(s);
                    set1.remove(s.no);
                }
                if(flag) break;
            }

            out.flush();
        }

        String s = "";
        for (Integer integer : robotQueue) {
            s += integer + " ";
        }
        out.print(s.substring(0, s.length() - 1));

    }


    public static class Com implements Comparator<Info> {
        @Override
        public int compare(Info o1, Info o2) {
            if (!o1.time.equals(o2.time)) {
                return o1.time.compareTo(o2.time);
            }
            if (!o1.type.equals(o2.type)) {
                return o1.type.compareTo(o2.type);
            }
            return o1.no.compareTo(o2.no);
        }
    }

    public static class Com2 implements Comparator<Info>{
        @Override
        public int compare(Info o1, Info o2) {
            return o1.time.compareTo(o2.time);
        }
    }
}
